package com.teach.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.dto.HotelRoomInfoDTO;
import com.teach.dto.HotelRoomInfoSearch;
import com.teach.entity.HotelRoomInfo;
import com.teach.entity.Shops;
import com.teach.mapper.HotelRoomInfoMapper;
import com.teach.service.HotelRoomInfoService;

@Service
public class HotelRoomInfoServiceImpl implements HotelRoomInfoService {
	
	@Autowired
	private HotelRoomInfoMapper mapper;
	
	@Autowired
	private MongoTemplate template;
	
	@Override
	public List<HotelRoomInfo> listAll() {
		return mapper.selectAll();
	}
	@Override
	public HotelRoomInfo getByShopIdAndRoomTypeId(Long shopId, Integer roomTypeId) {
		return mapper.getByTypeIdAndShopId(shopId, roomTypeId);
	}

	@Override
	public HotelRoomInfo get(Integer roomId) {
		return mapper.selectByPrimaryKey(roomId);
	}

	@Override
	public void add(HotelRoomInfo hotelRoomInfo) {
		mapper.insertSelective(hotelRoomInfo);
	}

	@Override
	public void update(HotelRoomInfo hotelRoomInfo) {
		mapper.updateByPrimaryKeySelective(hotelRoomInfo);
	}

	@Override
	public void delete(Integer roomId) {
		mapper.deleteByPrimaryKey(roomId);
	}


	@Override
	public List<HotelRoomInfoDTO> getRoomInfoDTO(Long id) {
		return mapper.selectByShopId(id);
	}

	@Override
	public HotelRoomInfo getRoomPrice(Long id,Integer roomTypeId) {
		return mapper.getPrice(id,roomTypeId);
	}

	@Override
	public int getRoomNum(Long id, Integer roomTypeId) {
		return mapper.getRoomNum(id, roomTypeId);
	}

	@Override
	public void updateRoomNum(HotelRoomInfo hotelRoomInfo) {
		mapper.updateByShopIdAndTypeId(hotelRoomInfo);
	}

	@Override
	public List<HotelRoomInfo> list(HotelRoomInfoSearch search) {
		PageInfo<HotelRoomInfo> page = PageHelper.startPage(search.getCurrent(), search.getRowMax(), false).doSelectPageInfo(()->{
			mapper.selectByShopId(search.getShopId());
		});
		return page.getList();
	}

	@Override
	public PageInfo<HotelRoomInfo> page(HotelRoomInfoSearch search) {
		// TODO Auto-generated method stub
		return null;
	}
}
